package cn.msi.project.service;

import java.util.List;

import cn.common.util.GeneralUtils;
import cn.msi.project.domain.Index;
import cn.msi.project.mapper.IndexMapper;

/**
 * 项目指标业务处理方法
 * 
 * @author Administrator
 * 
 */
public class IndexService {

	private IndexMapper indexMapper;

	/**
	 * 项目指标查询列表
	 * 
	 * @param index
	 * @return
	 */
	public String searchIndex(Index index) {
		List<Index> indexList = indexMapper.selectList(index);
		for (Index i : indexList) {
			addIndexNode(i);
		}
		return GeneralUtils.easyUI(indexList);
	}

	/**
	 * 递归查询子节点
	 * 
	 * @param index
	 */
	private void addIndexNode(Index index) {
		List<Index> indexList = indexMapper.selectListByParent(index.getIndexId());
		index.setChildren(indexList);
		for (Index i : indexList) {
			addIndexNode(i);
		}
	}

	/**
	 * 保存项目指标
	 * 
	 * @param index
	 */
	public void saveIndex(Index index) {
		indexMapper.insert(index);
	}

	public void setIndexMapper(IndexMapper indexMapper) {
		this.indexMapper = indexMapper;
	}
}
